package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.UserRoleCompanyAddDTO;
import org.jsola.hr.dto.UserRoleCompanyUpdateDTO;
import org.jsola.hr.entity.UserRoleCompanyDO;
import org.jsola.hr.query.UserRoleCompanyQuery;
import org.jsola.hr.service.IUserRoleCompanyService;
import org.jsola.hr.vo.UserRoleCompanyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 人员分管用工单位
 *
 * @author zhr
 */
@Component
public class UserRoleCompanyTestHelper extends BaseTestHelper {
    
    @Autowired
    private IUserRoleCompanyService userRoleCompanyService;

    /**
     * 生成add测试数据
     * @return UserRoleCompanyAddDTO
     */
    public UserRoleCompanyAddDTO getUserRoleCompanyAddDTO(){
        UserRoleCompanyAddDTO userRoleCompanyAddDTO = new UserRoleCompanyAddDTO();
        userRoleCompanyAddDTO.setUserId(getRandomValue("varchar",32));
        userRoleCompanyAddDTO.setRoleId(SafeKit.getLong(getRandomValue("bigint",11)));
        userRoleCompanyAddDTO.setChildCompanyId(getRandomValue("varchar",32));
        userRoleCompanyAddDTO.setEmployerId(getRandomValue("varchar",32));
        userRoleCompanyAddDTO.setIsAllEmployer(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        userRoleCompanyAddDTO.setIsAllChildCompany(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        return userRoleCompanyAddDTO;
    }


    /**
     * 生成update测试数据
     * @return UserRoleCompanyUpdateDTO
     */
    public UserRoleCompanyUpdateDTO getUserRoleCompanyUpdateDTO(UserRoleCompanyVO userRoleCompanyVO){
        return userRoleCompanyService.selectDOById(userRoleCompanyVO.getId(), SITE_ID).to(UserRoleCompanyUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return UserRoleCompanyQuery
     */
    public UserRoleCompanyQuery getUserRoleCompanyQuery() {
        UserRoleCompanyQuery userRoleCompanyQuery = new UserRoleCompanyQuery();
        List<UserRoleCompanyDO> userRoleCompanyDOList = userRoleCompanyService.list(new UserRoleCompanyDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(userRoleCompanyDOList)) {
            UserRoleCompanyDO userRoleCompanyDO = userRoleCompanyDOList.get(0);
            userRoleCompanyQuery = userRoleCompanyDO.to(UserRoleCompanyQuery.class);
        }
        return userRoleCompanyQuery;
    }

    /**
     * 保存示例
     * @return UserRoleCompanyVO
     */
    public UserRoleCompanyVO saveUserRoleCompanyExample(){
        UserRoleCompanyAddDTO addDTO = this.getUserRoleCompanyAddDTO();
        UserRoleCompanyVO userRoleCompanyVO = userRoleCompanyService.save(addDTO,buildTokenUser());
        return userRoleCompanyVO;
    }


}

